using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace ScreenKeyboardTester
{
    public partial class MainForm : Form
    {
        private TabControl? tabControl;
        private ScreenTestPanel? screenTestPanel;
        private KeyboardTestPanel? keyboardTestPanel;
        
        public MainForm()
        {
            SetupForm();
        }

        private void SetupForm()
        {
            this.Text = "屏幕和键盘测试工具";
            
            // 自适应屏幕大小 - 设置为屏幕大小的80%
            Screen primaryScreen = Screen.PrimaryScreen;
            int screenWidth = primaryScreen.Bounds.Width;
            int screenHeight = primaryScreen.Bounds.Height;
            int formWidth = (int)(screenWidth * 0.8);
            int formHeight = (int)(screenHeight * 0.8);
            
            this.Size = new Size(formWidth, formHeight);
            this.StartPosition = FormStartPosition.CenterScreen;
            this.MinimumSize = new Size(600, 400); // 设置最小窗口大小
            this.WindowState = FormWindowState.Normal;

            // 创建选项卡控件
            tabControl = new TabControl
            {
                Dock = DockStyle.Fill
            };

            // 屏幕测试选项卡
            var screenTab = new TabPage("屏幕测试");
            screenTestPanel = new ScreenTestPanel { Dock = DockStyle.Fill };
            screenTab.Controls.Add(screenTestPanel);

            // 键盘测试选项卡
            var keyboardTab = new TabPage("键盘测试");
            keyboardTestPanel = new KeyboardTestPanel { Dock = DockStyle.Fill };
            keyboardTab.Controls.Add(keyboardTestPanel);

            tabControl.TabPages.Add(screenTab);
            tabControl.TabPages.Add(keyboardTab);

            // 默认选择键盘测试选项卡
            tabControl.SelectedTab = keyboardTab;

            this.Controls.Add(tabControl);
        }

        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            screenTestPanel?.Cleanup();
            base.OnFormClosing(e);
        }
    }
}